package com.qfjy.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qfjy.config.RestTemplateConfig;
import com.qfjy.config.TuLingConfig;
import com.qfjy.entity.dto.Root;
import com.qfjy.entity.po.TuLing;
import com.qfjy.entity.po.UserMessage;
import com.qfjy.service.TulingService;
import com.qfjy.util.TuLingUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 小白
 * @Date 2021-11-14 13:43
 */
@Service
public class TulingImpl implements TulingService {
    @Autowired
    TuLingUtil tuLingUtil;
    @Autowired
    TuLingConfig tuLingConfig;
    @Autowired
    RestTemplateConfig restTemplateConfig;
    @Override
    public String getTuLing(UserMessage userMessage1){
        TuLing tuLin=tuLingUtil.getTuLingAPI(checkUserMessage(userMessage1));
        String tuOb=restTemplateConfig.restTemplate().postForObject(tuLingConfig.getUrl(),tuLin, String.class);
        System.out.println(tuOb);
        return tuOb;
    }
    public UserMessage checkUserMessage(UserMessage userMessage2){
        if(userMessage2.getCity()==null){
            userMessage2.setCity("南京");
        }
        if(userMessage2.getId()==null){
            userMessage2.setId(tuLingConfig.getUserId());
        }
        if(userMessage2.getProvince()==null){
            userMessage2.setProvince("南京");
        }
        if(userMessage2.getReqType()==null){
            userMessage2.setReqType(tuLingConfig.getStatusNum());
        }
        if(userMessage2.getStreet()==null){
            userMessage2.setStreet("南京");
        }
        if(userMessage2.getText()==null){
            userMessage2.setText("");
        }
        userMessage2.setKey(tuLingConfig.getApiKey());
        return userMessage2;
    }
}
